print("-----lua start------")
print(EDUI.Engine.GetVersion())

EDUI.Engine.SetStringGroup("English")
EDUI.Engine.SetXmlDir("test/test3/xml/")
print(EDUI.Engine.LoadRes("res/res.xml"))

print(EDUI.Engine.GetXmlDir())
print(EDUI.Engine.GetStringGroup())

local str = "hellow,this is a test of function SetClipboardText in lua."
print(EDUI.Engine.SetClipboardText(str))
print(EDUI.Engine.GetClipboardText())
print(EDUI.Engine.HasClipboardText())

local wnd = EDUI.Engine.LoadWindow("wnd/main.xml")

if not wnd then return end

local icon = EDUI.Engine.FindSurface("logo")
wnd:SetIcon(icon)


print("------1-----")
do
    print(wnd:GetName())
    print(wnd:GetID())
    print(wnd:GetFlags())
    wnd:SetTitle("aaa")
    local title = wnd:GetTitle()
    print(title)
    wnd:SetTitle(title)
end
print("-----2------")
do
    wnd:SetEnabled(false)
    print(wnd:IsEnabled())
    wnd:SetEnabled(true)
    print(wnd:IsEnabled())

    local parent = wnd:GetParent()
    print(parent)
    print(wnd:SetParent(0))
    print(wnd:SetParent(wnd))
end
print("-----3------")
do
    print(wnd:IsOK())
    --wnd:AskClose()
    --wnd:Close()
end
print("-----4------")
do
    local opacity = wnd:GetOpacity()
    print(wnd:SetOpacity(0.5))
    print(wnd:GetOpacity())
    wnd:SetOpacity(opacity)

    wnd:SetFocusCtrl(0)
    print(wnd:GetFocusCtrl())
    wnd:SetFocusCtrl(wnd:FindControl("edit1"))
    local focusctrl = wnd:GetFocusCtrl()
    print(focusctrl:GetName())
end
print("-----5------")
do
    local ctrl = wnd:FindControl("testfindcontrolchild")
    --local ctrl = wnd:FindControlByTabID(2)
    local name = ctrl:GetName()
    ctrl:SetName("testsetname")
    print(ctrl:GetName())
    ctrl:SetName(name)
    local tbaID = ctrl:GetTabID()
    ctrl:SetTabID(100)
    print(ctrl:GetTabID())
    ctrl:SetTabID(tbaID)
end
print("-----")
do
    local parent = wnd:FindControl("testfindcontrolparent")
    local child = parent:FindControl("testfindcontrolchild")
    --local child = parent:FindControlByTabID(2)
    print(child:GetName())
    local childparent = child:FindParent("testfindcontrolparent")
    print(childparent:GetName())
end
print("-----6------")
do
    local ctrlgetwnd = wnd:FindControl("testfindcontrolchild")
    print(ctrlgetwnd:GetName())
    local parent = ctrlgetwnd:GetParent()
    print(parent:GetName())
    local getwnd = ctrlgetwnd:GetWindow()
    print(getwnd:GetName())
end
print("-----7------")
do
    local ctrl = wnd:FindControl("testfindcontrolchild")
    local fl = ctrl:IsFloat()
    print("Float: default is",fl)
    ctrl:SetFloat(not fl)
    print(ctrl:IsFloat())
    ctrl:SetFloat(fl)

    local vs = ctrl:IsVisible()
    print("Visible: default is",vs)
    ctrl:SetVisible(not vs)
    print(ctrl:IsVisible())
    ctrl:SetVisible(vs)

    local en = ctrl:IsEnabled()
    print("Enabled: default is",en)
    ctrl:SetEnabled(not en)
    print(ctrl:IsEnabled())
    ctrl:SetEnabled(en)

    local me = ctrl:IsMouseEnabled()
    print("MouseEnabled: default is",me)
    ctrl:SetMouseEnabled(not me)
    print(ctrl:IsMouseEnabled())
    ctrl:SetMouseEnabled(me)

    local ke = ctrl:IsKeyboardEnabled()
    print("KeyboardEnabled: default is",ke)
    ctrl:SetKeyboardEnabled(not ke)
    print(ctrl:IsKeyboardEnabled())
    ctrl:SetKeyboardEnabled(ke)

    local fo = ctrl:IsFocused()
    print("Focused: default is",fo)
    if fo then
        ctrl:KillFocus()
        print(ctrl:IsFocused())
        ctrl:SetFocus()
    else
        ctrl:SetFocus()
        print(ctrl:IsFocused())
        ctrl:KillFocus()
    end

    print("dragwindow",ctrl:IsDragWindow())

    print("inrect:100,100",ctrl:IsInRect(100,100))
end
print("-----8------")
do
    local label = wnd:FindControl("testlabel")
    print("label:",label:GetName())
    label:SetText("label1")
    print(label:GetText())

    label:SetTranslateText(true)
    print(label:IsTranslateText())
    print(label:GetTranslateText())

    print("autowidth:",label:IsAutoWidth())
    label:SetAutoWidth(true)
    print("autowidth:",label:IsAutoWidth())

    print("autoheight:",label:IsAutoHeight())
    label:SetAutoHeight(true)
    print("autoheight:",label:IsAutoHeight())
end
print("-----9------")
do
    local minbtn = wnd:FindControl("min")
    local function minBtnClickEvent(button)
        print("minBtnClickEvent:",button:GetName())
        local wnd = button:GetWindow()
        wnd:MinWindow()
    end
    print("minbtn:SetEvent", minbtn:SetEvent("click", minBtnClickEvent))

    local closebtn = wnd:FindControl("close")
    print("closebtn:SetEvent", closebtn:SetEvent("click", function(button)
        print("closeBtnClickEvent:",button:GetName())
        local wnd = button:GetWindow()
        wnd:Close()
    end))
end
print("-----10------")
do
    local link1 = wnd:FindControl("link1")
    print("link1:SetEvent", link1:SetEvent("click", function(link)
        print("linkClickEvent:",link:GetName())
    end))
    link1:SetAutoHeight(true)
    link1:SetAutoWidth(true)
end
print("-----11------")
do
    local text1 = wnd:FindControl("link1")
    print("text1:",text1:GetText())
end
print("-----12------")
do
    local edit1 = wnd:FindControl("edit1")
    print("edit1:",edit1:GetName())
    print("edit1:SetEvent::textChange:", edit1:SetEvent("textChange", function(edit)
        print("edit1::textChange:")
    end))
    
    print("edit1:SetEvent::onEnter:", edit1:SetEvent("onEnter", function(edit)
        print("edit1::onEnter:")
    end))

    local wnd = edit1:GetWindow()
    wnd:SetTabCtrl(edit1)
    local tabctrl = wnd:GetTabCtrl()
    print("tabctrl:", tabctrl:GetName())
    wnd:TabCtrlNext()
    tabctrl = wnd:GetTabCtrl()
    print("tabctrl next:", tabctrl:GetName())
    wnd:SetTabCtrl(0)
    tabctrl = wnd:GetTabCtrl()
    print("tabctrl 0:", tabctrl)
    
    local root = wnd:GetRoot()
    print("root:", root:GetName())
end
print("-----13------")
do
    local checkbox1 = wnd:FindControl("checkbox1")
    print("checkbox1:",checkbox1:GetName())
    print("checkbox1:SetEvent::selected:", checkbox1:SetEvent("selected", function(checkbox)
        print("checkbox1::selected:", checkbox:IsSelected())
    end))

    local checkbox2 = wnd:FindControl("checkbox2")
    print("checkbox2:",checkbox2:GetName())
    print("checkbox2:SetEvent::selected:", checkbox2:SetEvent("selected", function(checkbox)
        print("checkbox2::selected:", checkbox:IsSelected())
    end))
    
    local tablelayout0checkbox = wnd:FindControl("tablelayout0checkbox")
    local tablelayout1checkbox = wnd:FindControl("tablelayout1checkbox")
    print(tablelayout1checkbox:GetGroup())
    tablelayout0checkbox:SetGroup("tablelayoutcheckbox")
    tablelayout1checkbox:SetGroup("tablelayoutcheckbox")
    print(tablelayout1checkbox:GetGroup())
    print(tablelayout0checkbox:BindTableLayout("tableLayout", 0))
    print(tablelayout1checkbox:BindTableLayout("tableLayout", 1))
    print("bind 0:", tablelayout0checkbox:GetBindTableLayoutName(), tablelayout0checkbox:GetBindTableLayoutIndex())
    print("bind 1:", tablelayout1checkbox:GetBindTableLayoutName(), tablelayout1checkbox:GetBindTableLayoutIndex())
    print()
    print("tablelayout1checkbox:SetEvent::selected:", tablelayout1checkbox:SetEvent("selected", function(checkbox)
        print("tablelayout1checkbox::selected:", checkbox:IsSelected())
        if not checkbox:IsSelected() then
            local wnd = checkbox:GetWindow()
            local checkbox1 = wnd:FindControl("checkbox1")
            --[[
                1:select or not
                2:do event or not
                3:notify others in this group
            ]]
            checkbox1:SetSelect(true)
            --checkbox1:SetSelect(true, false)
            --checkbox1:SetSelect(true, false, false)
        end
    end))
end
print("-----14------")
do
    local progress1 = wnd:FindControl("progress1")
    print("progress1:",progress1:GetName())
    print("progress1:SetEvent::progress:", progress1:SetEvent("progress", function(progress)
        print("progress1::progress:", progress:GetValue())
    end))

    local val = progress1:GetValue()
    progress1:SetValue(51)
    print("progress1 val:", progress1:GetValue())
    progress1:SetValue(val)

    val = progress1:GetMaxValue()
    progress1:SetMaxValue(90)
    print("progress1 maxval:", progress1:GetMaxValue())
    progress1:SetMaxValue(val)

    val = progress1:GetMinValue()
    progress1:SetMinValue(10)
    print("progress1 minval:", progress1:GetMinValue())
    progress1:SetMinValue(val)

    print(progress1:GetType())
end
print("-----15------")
do
    local slider1 = wnd:FindControl("slider1")
    print("slider1:",slider1:GetName())
    print("slider1:SetEvent::progress:", slider1:SetEvent("progress", function(slider)
        print("slider1::progress:", slider:GetValue())
    end))

    local step = slider1:GetStep()
    slider1:SetStep(10)
    print(slider1:GetStep())
    slider1:SetStep(step)

    print(slider1:SetValue(51))
    print(slider1:GetValue())
end
print("-----16------")
do
    local scrollbar1 = wnd:FindControl("scrollbar1")
    print("scrollbar1:",scrollbar1:GetName())
    print("scrollbar1:SetEvent::scroll:", scrollbar1:SetEvent("scroll", function(scrollbar)
        print("scrollbar1::scroll:", scrollbar:GetValue())
    end))
    print("scrollbar1:SetEvent::btn1Click:", scrollbar1:SetEvent("btn1Click", function(scrollbar)
        print("scrollbar1::btn1Click:", scrollbar:GetValue())
    end))
    print("scrollbar1:SetEvent::btn2Click:", scrollbar1:SetEvent("btn2Click", function(scrollbar)
        print("scrollbar1::btn2Click:", scrollbar:GetValue())
    end))
end
print("-----17------")
do
    local ctrl = wnd:FindControl("testfindcontrolchild")
    ctrl:SetColor("dst:bk;color:#FFFF0000;")
    ctrl:SetImage("dst:bk;image:(img:logo;center:true;);")
    local minbtnimg = "dst:(normal,hot,pressed);status:(img:min;size:30,25;num:3;type:v1;);"
    local minbtn = wnd:FindControl("min")
    minbtn:SetStatusImage(minbtnimg)
end
print("-----18------")
do
    print("width:", wnd:GetWidth()) 
    print("height:", wnd:GetHeight())

    local pos = wnd:GetPos()
    wnd:SetPos(100, 100)
    print("pos:", wnd:GetPos())
    wnd:SetPos(pos.x, pos.y)

    local size = wnd:GetSize()
    wnd:SetSize(200, 200)
    print("size:", wnd:GetSize())
    wnd:SetSize(size.w, size.h)

    local rc = wnd:GetRect()
    wnd:SetRect(0, 0, 200, 200)
    print("size:", wnd:GetRect())
    wnd:SetRect(rc.x, rc.y, rc.w, rc.h)

    local maxsz = wnd:GetMaxSize()
    wnd:SetMaxSize(1000, 1000)
    print("max size:", wnd:GetMaxSize())
    wnd:SetMaxSize(maxsz.w, maxsz.h)

    local minsz = wnd:GetMinSize()
    wnd:SetMinSize(100, 100)
    print("min size:", wnd:GetMinSize())
    wnd:SetMinSize(minsz.w, minsz.h)

    local caprc = wnd:GetCaptionRect()
    print(wnd:SetCaptionRect(0, 0, 0, 100))
    print("caption rect:", wnd:GetCaptionRect())
    wnd:SetCaptionRect(caprc.x, caprc.y, caprc.w, caprc.h)

    local szbox = wnd:GetSizeBox()
    print(wnd:SetSizeBox(3, 3, 3, 3))
    print("szbox rect1:", wnd:GetSizeBox())
    wnd:SetSizeBox(szbox.l, szbox.t, szbox.r, szbox.b)

end
collectgarbage("collect")
print("-----19------")
    local timer = wnd:AddTimer(500, function(id, interval, wnd)
        print(id, interval, wnd:GetName())
        return interval
    end)
print("-----20------")
    local gifctrl = wnd:FindControl("testgif")
    if gifctrl then
        local gif = gifctrl:GetAnimation()
        if gif then
            print(gif:FrameCount())
        end
    end
print("-----21------")
wnd:MinWindow()
wnd:MaxWindow()
wnd:RestoreWindow()
wnd:HideWindow()
wnd:ShowWindow()
print("-----lua end------")
